import * as YvanUI from "yvan-ui-wotu";

const _ = YvanUI.lodash

const React = YvanUI.React

interface Ref {

}

export default class DemoPlace extends YvanUI.Scope<void, Ref> {

    main = this.$$({
        repeats: 1
    })

    v = 0
    place1 = Symbol()

    vjson = {
        title: '动态界面2',
        items: [
            {
                view: 'form',
                items: [
                    {
                        view: 'card',
                        rows: [
                            {
                                cols: [
                                    {
                                        view: 'number',
                                        bind: 'main.repeats',
                                        label: '压测数量',
                                    }
                                ]
                            },
                            {
                                cols: [
                                    this.place1
                                ]
                            }
                        ]
                    }

                ]
            }
        ],
        footer: [
            {
                view: 'button',
                text: '创建',
                type: 'primary',
                onClick: () => {
                    this.v++
                    const vjson: any[] = []
                    for (let i = 0; i < this.main.repeats; i++) {
                        vjson.push({
                            view: 'text',
                            bind: `main.tr-${this.v}-${i}`,
                            label: `输入框-${this.v}-${i}`,
                            ref: `tr-${this.v}-${i}`
                        })
                    }

                    const t1 = new Date()
                    YvanUI.renderPlace(this, this.place1, vjson)
                    const cost = new Date().getMilliseconds() - t1.getMilliseconds()
                    YvanUI.showInfo(`耗时 ${cost} 毫秒`)
                }
            }
        ]
    }

}